package org.example.struct.array2;

/**
 * @author liyishan
 * @date 2024/8/30 10:00
 * @apiNote
 */

public class Test03153SumDigitDifferences {

    public static void main(String[] args) {
        int[] nums ={13,23,12};
        long res = sumDigitDifferences(nums);
        System.out.println(res);
    }
    public static long sumDigitDifferences(int[] nums) {
        long res = 0;
        int n = nums.length;
        while (nums[0] > 0) {
            int[] cnt = new int[10];
            for (int i = 0; i < n; i++) {
                cnt[nums[i] % 10]++;
                nums[i] /= 10;
            }
            for (int i = 0; i < 10; i++) {
                res += (long) (n - cnt[i]) * cnt[i];
            }
        }
        return res / 2;
    }

}
